var gulp = require('gulp');
var rjs = require('requirejs');
var watch = require('gulp-watch');

gulp.task('build', function(cb) {
    rjs.optimize({
        baseUrl: 'app',
        paths: {
            jquery: 'vendor/jquery.min',
            text: 'vendor/text.min',
            knockout: 'vendor/knockout-min',
            template: 'vendor/template',
            underscore:'vendor/underscore-min'
        },
        dir: './www-dist',
        modules: [{
            name: 'controllers/baseController'
        }, {
            name: 'controllers/homeController',
            exclude: ["controllers/baseController"]
        }, {
            name: 'controllers/memberController',
            exclude: ["controllers/baseController"]
        }, {
            name: 'controllers/productController',
            exclude: ["controllers/baseController"]
        }, ],
        fileExclusionRegExp: /^(r|build|config|config2)\.js|modules\/*$/,
        optimizeCss: 'standard',
        removeCombined: true,
    }, function(buildResponse) {
        console.log('build response:', buildResponse);
        cb();
    }, cb);
});

// var watcher = gulp.watch('app/modules/**/*.js', ['build']);
// watcher.on('change', function(event) {
//     console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
// });

gulp.task('default', ['build']);
